<template>
	<view class="OuterBg">
		<view class="user-info flex-col">
			<!-- #ifndef  H5 -->
			<u-sticky offset-top="0" h5-nav-height="0" bg-color="transparent">
				<u-navbar title="配送收益" :title-bold="true" :is-fixed="false" :border-bottom="false"
					:background="{ background: 'rgba(256,256, 256,' + percent + ')' }"
					:back-icon-color="percent > 0.5 ? '#000' : '#fff'" :title-color="percent > 0.5 ? '#000' : '#fff'">
				</u-navbar>
			</u-sticky>
			<!-- #endif -->
			<u-gap height="200"></u-gap>
		</view>
		<!-- income -->
		<view class="body p-20" :style="{
			top: '-160rpx'
		}">

			<view class="top-tab item-tab">
				<view class="title flex row-left">
					<view>
						<u-line direction="col" length="30rpx" color="rgba(64, 115, 250, 1)" :hair-line="false"
							border-width="6rpx" margin="0rpx 10rpx"></u-line>
					</view>
					<text>{{$zhTran('收益')}}</text>
				</view>
				<view class="data-tab flex row-around m-t-50">
					<view>
						<view class="number">{{clwhInfo.wait_confirm|| 0}}</view>
						<view class="desc">{{$zhTran('待确认收益')}}</view>
					</view>
					<view>
						<view class="number">{{clwhInfo.been_confirm||0}}</view>
						<view class="desc">{{$zhTran('已确认收益')}}</view>
					</view>
				</view>

				<view class="withdraw-btn" @click="toWithdraw">
					<text class="m-r-10">{{$zhTran('去提现')}}</text>
					<u-icon name="arrow-right" color="#fff"></u-icon>
				</view>
			</view>


			<view class="order-list">
				<mescroll-uni ref="mescrollRef" :fixed="false" :up="{
				  auto: false,
				  noMoreSize: 3,
				  empty: {
				  	icon: $getImageUri('resource/image/shopapi/uniapp/empty/order.png'),
				  	tip: $zhTran('暂无数据~'),
				  	fixed: true
				  }
			  }" :down="{ auto: false }" @init="mescrollInit" @down="downCallback" @up="upCallback">
					<view class="order-tab" v-for="(item, idx) in profitLists" :key="idx">
						<view class="flex row-between order p-b-20 m-b-20">
							<view class="sn flex">
								<u-avatar :src="$getImageUri('resource/image/shopapi/clwh/logo.png')" size="36"
									class="m-r-10 m-t-5"></u-avatar>
								<text>{{$zhTran('订单编号：')}}{{item.order_info.sn}}</text>
							</view>
							<view :class="[
										'status',
										`status--${orderStatus[item.order_info.order_status]['style']}`
									]">{{item.order_info.order_status_desc}}</view>
						</view>
						<view class="flex row-between m-b-10">
							<view class="profit">{{$zhTran('分润金额')}}</view>
							<price :content="item.profit" prefix="￥" color="rgba(238, 10, 37, 1)" font-weight="bold"
								main-size="46rpx" minor-size="30rpx" />
						</view>
						<view class="desc m-b-10">{{$zhTran('分润状态：')}}{{item.status_desc}}</view>
						<view class="desc">{{$zhTran('确认时间：')}}{{item.settlement_time}}</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		apiCloudWarehouseInfo,
		apiCloudWarehouseProfitList
	} from "@/api/cloud_warehouse"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				clwhInfo: {},
				percent: 0,
				profitLists: [],
				orderStatus: {
					1: {
						style: 'warning',
					},
					2: {
						style: 'primary',
					},
					3: {
						style: 'info',
					},
				},
			}
		},
		methods: {
			getCloudWarehouseInfo() {
				apiCloudWarehouseInfo().then(res => {
					this.clwhInfo = this.$zhTran(res);
				})
			},
			refreshOrderData() {
				this.$nextTick(() => {
					this.mescroll.resetUpScroll()
				})
			},

			// 初始化Mescroll
			mescrollInit(mescroll) {
				console.log(mescroll);
				this.mescroll = mescroll;
			},
			// 上拉加载更多
			upCallback({
				num,
				size
			}) {
				apiCloudWarehouseProfitList({
					page_no: num,
					page_size: size,
				}).then(({
					lists,
					count,
					extend
				}) => {
					if (num === 1) this.profitLists = []
					this.profitLists = [...this.profitLists, ...lists]
					this.profitLists = this.$zhTran(this.profitLists)
					this.mescroll.endSuccess(lists.length, count)
				}).catch(err => {
					this.mescroll.endErr()
				})
			},
			onPageScroll(e) {
				const top = uni.upx2px(100)
				const {
					scrollTop
				} = e
				this.percent = scrollTop / top > 1 ? 1 : scrollTop / top
			},
			toWithdraw() {
				this.$Router.push({
					path: '/bundle/pages/user_withdraw/user_withdraw',
					query: {}
				})
			},
		},
		onShow() {
			this.getCloudWarehouseInfo()
			this.refreshOrderData()
		}
	}
</script>

<style lang="scss" scoped>
	.user-info {
		background-color: rgba(64, 115, 250, 1);
		background-size: 100% auto;
		background-repeat: no-repeat;
		box-sizing: border-box;

		&.u-skeleton-rect {
			height: 518rpx;
		}
	}

	.body {
		position: relative;

		.top-tab {
			width: 100%;
			padding: 30rpx;
			background-color: #fff;
			border-radius: 20rpx;
		}

		.item-tab {
			margin-bottom: 30rpx;
			position: relative;


			.withdraw-btn {
				position: absolute;
				right: 0;
				top: 20rpx;
				border-radius: 50rpx 0 0 50rpx;
				color: #fff;
				background-color: rgba(255, 141, 26, 1);
				font-size: 26rpx;
				padding: 15rpx 25rpx;
			}

			.title {
				color: rgba(47, 47, 47, 1);
				font-size: 28rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			.data-tab {
				padding: 0 30rpx;
				background-color: #fff;
				border-radius: 20rpx;
				text-align: center;

				.number {
					color: rgba(58, 58, 58, 1);
					font-size: 38rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
				}

				.desc {
					color: rgba(128, 128, 128, 1);
					font-size: 26rpx;
				}
			}
		}
	}


	.order-list {
		flex: 1;
		min-height: 0;
		position: relative;

		.order-tab {
			background-color: #fff;
			border-radius: 6rpx;
			margin-bottom: 20rpx;
			padding: 20rpx;

			.order {
				border-bottom: 1px solid rgba(241, 241, 241, 1);

				.sn {
					font-size: 26rpx;
				}

				.status {
					border-radius: 6rpx;
					padding: 10rpx;

					&--warning {
						color: rgba(255, 141, 26, 1);
						background-color: rgba(255, 240, 224, 1);
					}

					&--primary {
						background-color: rgba(242, 246, 255, 1);
						color: rgba(64, 115, 250, 1);
					}

					&--info {
						color: rgba(159, 159, 159, 1);
						background-color: rgba(241, 241, 241, 1);
					}
				}
			}

			.profit {
				font-size: 32rpx;
				font-weight: bold;
			}

			.desc {
				color: rgba(104, 104, 104, 1);
			}
		}
	}
</style>